home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / kane / dvifile_p.h < prev    next >
Text File  |  1990-10-01  |  10KB  |  314 lines

  1.  
  2. Date:        20-MAR-1989 17:20:04 GMT
  3. From:        PHYOKANE@CS8700.UCG.IE
  4. To:        abbottp@ASTON.AC.UK
  5. Subject:        file dvifile_p.h
  6. sender:     hea"phyokane@cs8700.ucg.ie"  <phyokane@cs8700.ucg.ie>
  7.  
  8. /* -*-C-*- dvifile.h */
  9. /*-->dvifile*/
  10. /**********************************************************************/
  11. /****************************** dvifile *******************************/
  12. /**********************************************************************/
  13.  
  14. void
  15. dvifile(argc,argv,filestr)
  16. int   argc;            /* argument count */
  17. char* argv[];            /* argument strings */
  18. char* filestr;            /* DVI filename to process */
  19.  
  20. {
  21.  
  22. #define PAGENUMBER(p) ((p) < 0 ? (page_count + 1 + (p)) : (p))
  23.  
  24.     register INT16 i,j,m;    /* loop indices */
  25.     register INT16 swap;    /* swap storage */
  26.     register struct font_entry *p;
  27.  
  28.     INT16 m_begin,m_end,m_step;    /* loop limits and increment */
  29.     INT16 list[3];        /* index list for sort */
  30.     char tempstr[MAXSTR];    /* temporary string storage */
  31.     int the_char;
  32.     int s;
  33.     int slot;
  34.     int n_slots;
  35.     int fontsize;
  36.     int pfont_size;
  37.     int pfont_n;
  38.     struct font_entry *bigfont;
  39.     struct printer_font *pptr;
  40.     /*
  41.     Establish the default  font file  search order.  This  is done  here
  42.     instead of  in  initglob()  or  option(),  because  both  could  set
  43.     fontlist[].
  44.  
  45.     By default, the search list contains  names for the PK, GF, and  PXL
  46.     font  files;  that  order   corresponds  to  increasing  size   (and
  47.     therefore, presumably, increasing  processing cost)  of font  raster
  48.     information.  This search  order may  be overridden at  run time  by
  49.     defining an alternate one in the environment variable FONTLIST;  the
  50.     order of  the  strings  "PK",  "GF",  and  "PXL"  in  that  variable
  51.     determines the search  order, and  letter case  is NOT  significant.
  52.     The  substrings  may  be  separated   by  zero  or  more   arbitrary
  53.     characters, so  the  values  "PK-GF-PXL", "PK  GF  PXL",  "PKGFPXL",
  54.     "PK;GF;PXL", "PK/GF/PXL"  are all  acceptable,  and all  choose  the
  55.     default search  order.   This  flexibility  in  separator  character
  56.     choice is occasioned  by the  requirement on some  systems that  the
  57.     environment variable have the syntax of a file name, or be a  single
  58.     "word".  If  any  substring  is  omitted, then  that  font  will  be
  59.     excluded from consideration.  Thus, "GF" permits the use only of  GF
  60.     font files.
  61.  
  62.     The indexes gf_index, pk_index, and pxl_index are in -1 .. 2, and at
  63.     least one must be non-negative.  A negative index excludes that font
  64.     file type from the search.
  65.     */
  66.  
  67.     /* Note that non-negative entries in list[] are UNIQUE. */
  68.     list[0] = gf_index = (INT16)strid2(fontlist,"GF");
  69.     list[1] = pk_index = (INT16)strid2(fontlist,"PK");
  70.     list[2] = pxl_index = (INT16)strid2(fontlist,"PXL");
  71.  
  72.     for (i = 0; i < 3; ++i)    /* put list in non-decreasing order */
  73.     for (j = i+1; j < 3; ++j)
  74.         if (list[i] > list[j])
  75.         {
  76.         swap = list[i];
  77.         list[i] = list[j];
  78.         list[j] = swap;
  79.         }
  80.     for (i = 0; i < 3; ++i)    /* assign indexes 0,1,2 */
  81.     if (list[i] >= 0)
  82.     {
  83.             if (list[i] == gf_index)
  84.         gf_index = i;
  85.             else if (list[i] == pk_index)
  86.         pk_index = i;
  87.             else if (list[i] == pxl_index)
  88.         pxl_index = i;
  89.     }
  90.  
  91.     if ((gf_index < 0) && (pk_index < 0) && (pxl_index < 0))
  92.     (void)fatal("dvifile():  FONTLIST does not define at least one of \
  93. GF, PK, or PXL fonts");
  94.  
  95.     (void)dviinit(filestr);    /* initialize DVI file processing */
  96.  
  97.     (void)devinit(argc,argv);    /* initialize device output */
  98.  
  99.     (void)readpost();
  100.     (void)FSEEK(dvifp, 14L, 0); /* position past preamble */
  101.     (void)getbytes(dvifp, tempstr,
  102.     (BYTE)nosignex(dvifp,(BYTE)1)); /* flush DVI comment */
  103.  
  104.     cur_page_number = 0;
  105.  
  106.  
  107. #if    (HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2)
  108.     /* print pages in reverse order because of laser printer */
  109.     /* page stacking */
  110.     if (backwards)
  111.     {
  112.     m_begin = 1;
  113.     m_end = page_count;
  114.     m_step = 1;
  115.     }
  116.     else    /* normal device order */
  117.     {
  118.     m_begin = page_count;
  119.     m_end = 1;
  120.     m_step = -1;
  121.     }
  122.  
  123. #else
  124.   /* NOT (HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2) */
  125.     /* print pages in forward order for most devices */
  126.     if (backwards)
  127.     {
  128.     m_begin = page_count;
  129.     m_end = 1;
  130.     m_step = -1;
  131.     }
  132.     else
  133.     {
  134.     m_begin = 1;
  135.     m_end = page_count;
  136.     m_step = 1;
  137.     }
  138. #endif /* (HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2) */
  139.  
  140.     for (i = 0; i < npage; ++i)        /* make page numbers positive */
  141.     {                    /* and order pairs non-decreasing */
  142.     page_begin[i] = PAGENUMBER(page_begin[i]);
  143.     page_end[i] = PAGENUMBER(page_end[i]);
  144.     if (page_begin[i] > page_end[i])
  145.     {
  146.         swap = page_begin[i];
  147.         page_begin[i] = page_end[i];
  148.         page_end[i] = swap;
  149.     }
  150.     }
  151. /* First pass over pages and setup font download information */
  152.  
  153.     for (m = m_begin; ; m += m_step)
  154.     {
  155.     for (i = 0; i < npage; ++i)    /* search page list */
  156.         if ( IN(page_begin[i],m,page_end[i]) &&
  157.             (((m - page_begin[i]) % page_step[i]) == 0) )
  158.         {
  159.         if (!quiet)        /* start progress report */
  160.             (void)fprintf(stderr,"[%d", m);
  161.         cur_page_number++;/* sequential page number 1..N */
  162.         cur_index = m-1;    /* remember index globally */
  163.         checkpage(page_ptr[cur_index]);
  164.         if (!quiet)        /* finish progress report */
  165.             (void)fprintf(stderr,"] ");
  166.         break;
  167.         }
  168.     if (m == m_end)            /* exit loop after last page */
  169.         break;
  170.     }
  171. if (!quiet)        /* finish progress report */
  172.     (void)fprintf(stderr,"\n");
  173.  
  174. /* Initialize the printer fonts */
  175. for (pf = FIRSTPRINTERFONT; pf <= LASTPRINTERFONT; pf++)
  176. {
  177.     printer_fonts[pf].slots_free = 190;
  178.     for (s = 0; s < 190; s++)
  179.     {
  180.         printer_fonts[pf].char_slots[s].tex_char = -1;
  181.         printer_fonts[pf].char_slots[s].tex_font = NULL;
  182.     }
  183. }
  184. /*    Pack the TeX fonts into printer fonts
  185.  
  186.     WHILE there are unassigned TeX fonts
  187.         select the largest TeX font
  188.         if possible assign all of the TeX font  
  189.             to the FIRST SMALLEST SPACE free in the printer fonts
  190.         else
  191.             find the FIRST LARGEST SPACE free and assign as much
  192.             of the TeX font as will fit
  193. */
  194. do {
  195.     /* First....find the largest TeX font left....*/
  196.     fontsize = 0;
  197.     bigfont = NULL;
  198.     fontptr = hfontptr;
  199.     while ((fontptr != (struct font_entry *)NULL))
  200.     {
  201.     if ((fontptr->used_chars - fontptr->assigned_chars) > fontsize)
  202.     {
  203.         fontsize = fontptr->used_chars - fontptr->assigned_chars;
  204.         bigfont = fontptr;
  205.     }
  206.     fontptr = fontptr->next;
  207.     }
  208.     if (bigfont == NULL) break;  /* All TeX fonts assigned */
  209.     fontptr = bigfont;
  210.     fontsize =  (fontsize > 190) ? 190 : fontsize;
  211.  
  212.     /* Next... find a printer font to put it in.... */
  213.     pfont_size = 1000;
  214.     for (pf = FIRSTPRINTERFONT; pf <= LASTPRINTERFONT; pf++)
  215.     {
  216.     if ((printer_fonts[pf].slots_free >= fontsize) &&
  217.         (printer_fonts[pf].slots_free < pfont_size))
  218.     {        
  219.         pfont_size = printer_fonts[pf].slots_free;
  220.         pfont_n = pf;
  221.     }
  222.     }
  223.     /* ...if there is no big slot then split this font... */
  224.     /*    putting the first bit into the bigest free slot */
  225.     if (pfont_size > 190)
  226.     {    
  227.     pfont_size = 0;        
  228.     for (pf = FIRSTPRINTERFONT; pf <= LASTPRINTERFONT; pf++)
  229.     {
  230.         if (printer_fonts[pf].slots_free > pfont_size)
  231.         {        
  232.             pfont_size = printer_fonts[pf].slots_free;
  233.             pfont_n = pf;
  234.         }
  235.     }
  236.     }
  237.     if (pfont_size == 0)
  238.     (void)fatal( "dvifile(): Need more printer fonts");
  239.     pf = pfont_n;
  240. /* Printer font number pf has pfont_size slots available to take characters
  241.    from TeX font fontptr */
  242.     (void)fprintf(stderr,
  243. "[Assigning %d characters from %s (mag = %g) to printer font %d]\n",
  244.     (fontsize <= pfont_size) ? fontsize : pfont_size,
  245.     fontptr->n,(fontptr->font_mag)/1500.0,pf);
  246.     for (the_char = FIRSTPXLCHAR; the_char <= LASTPXLCHAR; the_char++)
  247.     {
  248.     if (printer_fonts[pf].slots_free == 0)
  249.         break;
  250.     if (fontptr->ch[the_char].isloaded == FALSE)    /* Not used    */
  251.         continue;
  252.     if (fontptr->ch[the_char].lj_font != 65535)/* Already assigned */
  253.         continue;
  254.     slot = 190 - printer_fonts[pf].slots_free--;
  255.     printer_fonts[pf].char_slots[slot].tex_char = the_char;
  256.     printer_fonts[pf].char_slots[slot].tex_font = fontptr;
  257.     fontptr->ch[the_char].lj_char = slot;
  258.     fontptr->ch[the_char].lj_font = pf;
  259.     fontptr->assigned_chars++;
  260.     }
  261.     if ( printer_fonts[pf].slots_free == pfont_size ) /* Nothing happened !!!*/
  262.         fontptr->assigned_chars = fontptr->used_chars;/* Zero size font ??   */
  263. } while (TRUE);
  264. /* .... and finally download the fonts to the printer.... */
  265. for (pf = FIRSTPRINTERFONT; pf <= LASTPRINTERFONT; pf++)
  266. {
  267.     pptr = &printer_fonts[pf];
  268.     if (pptr->slots_free == 190) continue;
  269.     slot = 0;
  270.     n_slots = 190 - pptr->slots_free;
  271.     (void)fprintf(stderr,"[Loading printer font %d with %d characters]\n",
  272.             pf,n_slots);    
  273.     (void)makefont(pptr,n_slots);
  274.     do {
  275.     fontptr = pptr->char_slots[slot].tex_font;   
  276.     while ( (slot < n_slots) &&
  277.          (pptr->char_slots[slot].tex_font == fontptr) )
  278.         {
  279.         loadchar(pptr->char_slots[slot].tex_char,MAP_CHAR(slot));
  280.         ++slot;
  281.     }
  282.     } while ( slot < n_slots );
  283. }
  284.  
  285. #if    (HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2)
  286.     pf = -1;
  287. #endif
  288.  
  289.  
  290. /* Finally pass over pages and print them */
  291.     for (m = m_begin; ; m += m_step)
  292.     {
  293.     for (i = 0; i < npage; ++i)    /* search page list */
  294.         if ( IN(page_begin[i],m,page_end[i]) &&
  295.             (((m - page_begin[i]) % page_step[i]) == 0) )
  296.         {
  297.         if (!quiet)        /* start progress report */
  298.             (void)fprintf(stderr,"[%d", m);
  299.         cur_page_number++;/* sequential page number 1..N */
  300.         cur_index = m-1;    /* remember index globally */
  301.         prtpage(page_ptr[cur_index]);
  302.         if (!quiet)        /* finish progress report */
  303.             (void)fprintf(stderr,"] ");
  304.         break;
  305.         }
  306.     if (m == m_end)            /* exit loop after last page */
  307.         break;
  308.     }
  309.  
  310.     (void)devterm();        /* terminate device output */
  311.  
  312.     (void)dviterm();        /* terminate DVI file processing */
  313. }
  314.